package com.team5101.controller;


import com.team5101.entity.Order;

import com.team5101.entity.User;
import com.team5101.service.IUserService;

import com.team5101.utils.R;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private IUserService iUserService;

    @RequestMapping("/list")
    @ResponseBody
    public R userList(){
        return R.ok(iUserService.userList());
    }
//    public R userList(PageDTO pageDTO) { //查寻所有用户信息
//
//        if(pageDTO.getCurPage() == null ){
//            pageDTO.setCurPage(1); // 如果没传参，默认显示第1页
//        }
//        if(pageDTO.getPageSize() == null){
//            pageDTO.setPageSize(PAGE_SIZE); //默认每页的条数
//        }
//        System.out.println(pageDTO);
//        PageHelper.startPage(pageDTO.getCurPage(),pageDTO.getPageSize());
//        List<User> users = iUserService.userList();
//        System.out.println("======"+users);
//       PageInfo<User>pageInfo=new PageInfo<User>(users);
//        System.out.println("-----"+pageInfo);
//        return R.ok(pageInfo);
//    }


    @RequestMapping("/delete")
    @ResponseBody
    public R userGo(String uTelephone) {//前端传一个手机号过来
        System.out.println(uTelephone);
        int i = iUserService.userDelete(uTelephone);
        if(i>0){
            return R.ok();
        }else{
            return R.error();
        }
    }

    @RequestMapping("/query")
    @ResponseBody
    public R queryUser(String uTelephone){
        System.out.println(uTelephone);
        List<User> userquery = iUserService.userQuery(uTelephone);
        if(userquery!=null){
           return R.ok(userquery);
        }else{
            return R.error();
        }
    }
    @RequestMapping("/order")
    public R userOrder(String orderPhone){
        System.out.println(orderPhone);
        List<Order> orders = iUserService.userOrder(orderPhone);
        for(Order d:orders)
        System.out.println(d);
        if(orders!=null){
            return R.ok(orders);
        }else {
            return R.error();
        }
    }
}